package com.guguskins.back.controller;


import com.guguskins.back.entity.GuRole;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-07-16
 */
@RestController
@RequestMapping("/gu-role")
public class GuRoleController {

    @Autowired
    private GuRoleService roleService;

    @GetMapping("/back-list")
    public ResultVo getList() {
        List<GuRole> list = roleService.list();
        return ResultVo.success(list);
    }



    @PostMapping("/back-add")
    public ResultVo add(@RequestBody GuRole role) {
        int result = roleService.add(role);
        if (result > 0) {
            return ResultVo.success("添加成功");
        }
        return ResultVo.fail("fail", "添加失败");
    }

    @PutMapping("/back-edit")
    public ResultVo edit(@RequestBody GuRole role) {
        int result = roleService.edit(role);
        if (result > 0) {
            return ResultVo.success("修改成功");
        }
        return ResultVo.fail("fail", "修改失败");
    }

    @PutMapping("/back-enable")
    public ResultVo enable(@RequestParam int[] ids) {
        int result = roleService.updateStatus(ids, 1);
        if (result > 0) {
            return ResultVo.success("启用成功");
        }
        return ResultVo.fail("fail", "启用失败");
    }

    @PutMapping("/back-disable")
    public ResultVo disable(@RequestParam int[] ids) {
        int result = roleService.updateStatus(ids, 0);
        if (result > 0) {
            return ResultVo.success("禁用成功");
        }
        return ResultVo.fail("fail", "禁用失败");
    }

    @PostMapping("/back-permission")
    public ResultVo permission(@RequestBody GuRole role) {

        return ResultVo.fail("success", null);
    }
}

